package com.panopset.nls;

import java.util.HashMap;
import java.util.Map;

import javax.swing.ImageIcon;

/**
 * Name, flag, and locale of a language.
 *
 * @author Karl Dinwiddie
 *
 */
public final class Language {

    /**
     * Languages map.
     */
    private static Map<String, Language> languages =
        new HashMap<String, Language>();

    /**
     * Locale name.
     */
    private final String localeNm;

    /**
     * 16x16 Flag image .png for this language.
     */
    private final ImageIcon flagImage;

    static {
        for (String ln : FlagIcons.getResourceList()) {
            languages.put(ln, new Language(ln));
        }
    }

    /**
     *
     * @param localeName
     *            Locale name.
     */
    private Language(final String localeName) {
        this.localeNm = localeName;
        this.flagImage = FlagIcons.getFlag(localeName);
    }

    /**
     *
     * @param localeName
     *            Locale name.
     * @return Language for a given localeName.
     */
    public static Language getLanguage(final String localeName) {
        return languages.get(localeName);
    }

    /**
     *
     * @return Portable Network Graphics (.png) flag image for this Language.
     */
    public ImageIcon getFlagImage() {
        return flagImage;
    }

    /**
     * @return Locale name for this language.
     */
    public String getLocaleName() {
        return localeNm;
    }

}
